package util

import (
	"github.com/sirupsen/logrus"
	"net"
	"strings"
)

func GetLocalIP() (ip string) {
	conn, err := net.Dial("udp", "8.8.8.8:80")
	if err != nil {
		logrus.Error("net: get Local Address failed!", err)
		return
	}
	defer conn.Close()
	localAddr := conn.LocalAddr().(*net.UDPAddr)
	ip = strings.SplitAfter(localAddr.IP.String(), ":")[0]
	return
}
